import {createRouter, createWebHistory} from 'vue-router'
import {ElMessage} from "element-plus";

const router = createRouter({
    history: createWebHistory(import.meta.env.BASE_URL),
    routes: [
        {
            path: '/',
            name: '登录',
            component: () => import('@/views/Login.vue'),
            redirect: '/login',
        },
        {
            path: '/PHARMACIST',
            name: '药师',
            beforeEnter(to, from, next) {
                let type = localStorage.getItem("role");
                if (type === "PHARMACIST") next();
                else {
                    ElMessage.error('当前用户无权限访问此页面！')
                    return next('/')
                }
            },
            component: () => import('@/views/pharmacist/Manager.vue'),
            redirect: '/PHARMACIST/home',
            children: [
                {path: '/PHARMACIST/home', component: () => import('@/views/pharmacist/Home.vue')},
                {path: '/PHARMACIST/password', component: () => import('@/views/pharmacist/Password.vue')},
                {path: '/PHARMACIST/person', component: () => import('@/views/pharmacist/Person.vue')},
                {path: '/PHARMACIST/drug', component: () => import('@/views/pharmacist/Drug.vue')},
                {path: '/PHARMACIST/prescriptionItem', component: () => import('@/views/pharmacist/PrescriptionItem.vue')},
                {path: '/PHARMACIST/prescription', component: () => import('@/views/pharmacist/Prescription.vue')},
            ]
        },
        {
            path: '/ADMIN',
            name: '管理员',
            beforeEnter(to, from, next) {
                let type = localStorage.getItem("role");
                if (type === "ADMIN") next();
                else {
                    ElMessage.error('当前用户无权限访问此页面！')
                    return next('/')
                }
            },
            component: () => import('@/views/admin/Manager.vue'),
            redirect: '/ADMIN/home',
            children: [
                {path: '/ADMIN/person', component: () => import('@/views/admin/Person.vue')},
                {path: '/ADMIN/password', component: () => import('@/views/admin/Password.vue')},
                {path: '/ADMIN/home', component: () => import('@/views/admin/Home.vue')},
                {path: '/ADMIN/admin', component: () => import('@/views/admin/Admin.vue')},
                {path: '/ADMIN/pharmacist', component: () => import('@/views/admin/Pharmacist.vue')},
                {path: '/ADMIN/patients', component: () => import('@/views/admin/Patients.vue')},
                {path: '/ADMIN/department', component: () => import('@/views/admin/Department.vue')},
                {path: '/ADMIN/admissions', component: () => import('@/views/admin/Admissions.vue')},
                {path: '/ADMIN/registrationForm', component: () => import('@/views/admin/RegistrationForm.vue')},
                {path: '/ADMIN/doctor', component: () => import('@/views/admin/Doctor.vue')},
                {path: '/ADMIN/bed', component: () => import('@/views/admin/bed.vue')},
                {path: '/ADMIN/patientVisit', component: () => import('@/views/admin/PatientsVisit.vue')},
            ]
        },
        {
            path: '/PATIENT',
            name: '患者',
            beforeEnter(to, from, next) {
                let type = localStorage.getItem("role");
                if (type === "PATIENT") next();
                else {
                    ElMessage.error('当前用户无权限访问此页面！')
                    return next('/')
                }
            },
            component: () => import('@/views/patient/Manager.vue'),
            redirect: '/PATIENT/home',
            children: [
                {path: '/PATIENT/home', component: () => import('@/views/patient/Home.vue')},
                {path: '/PATIENT/person', component: () => import('@/views/patient/Person.vue')},
                {path: '/PATIENT/password', component: () => import('@/views/patient/Password.vue')},
                {path: '/PATIENT/reserve', component: () => import('@/views/patient/Reserve.vue')},
                {path: '/PATIENT/myRegistrationForm', component: () => import('@/views/patient/MyRegistrationForm.vue')},
                {path: '/PATIENT/myVisit', component: () => import('@/views/patient/MyVisit.vue')},
            ]
        },
        {
            path: '/SUPERADMIN',
            name: '超级管理员',
            beforeEnter(to, from, next) {
                let type = localStorage.getItem("role");
                if (type === "SUPERADMIN") next();
                else {
                    ElMessage.error('当前用户无权限访问此页面！')
                    return next('/')
                }
            },
            component: () => import('@/views/superAdmin/Manager.vue'),
            redirect: '/SUPERADMIN/home',
            children: [
                {path: '/SUPERADMIN/home', component: () => import('@/views/superAdmin/Home.vue')},
                {path: '/SUPERADMIN/person', component: () => import('@/views/superAdmin/Person.vue')},
                {path: '/SUPERADMIN/password', component: () => import('@/views/superAdmin/Password.vue')},
            ]
        },
        {
            path: '/DOCTOR',
            name: '医生',
            beforeEnter(to, from, next) {
                let type = localStorage.getItem("role");
                if (type === "DOCTOR") next();
                else {
                    ElMessage.error('当前用户无权限访问此页面！')
                    return next('/')
                }
            },
            component: () => import('@/views/doctor/Manager.vue'),
            redirect: '/DOCTOR/home',
            children: [
                {path: '/DOCTOR/home', component: () => import('@/views/doctor/Home.vue')},
                {path: '/DOCTOR/person', component: () => import('@/views/doctor/Person.vue')},
                {path: '/DOCTOR/password', component: () => import('@/views/doctor/Password.vue')},
                {path: '/DOCTOR/registration', component: () => import('@/views/doctor/Registration.vue')},
                {path: '/DOCTOR/myTask', component: () => import('@/views/doctor/MyTask.vue')},
                {path: '/DOCTOR/doctorPrescription', component: () => import('@/views/doctor/DoctorPrescription.vue')},
            ]
        },
        {path: '/register', component: () => import('@/views/Register.vue')},
        {path: '/login', component: () => import('@/views/Login.vue')}
    ]
})

export default router
